﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;

namespace LotteryVote
{
    public partial class RoleManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                Bind();
        }

        void Bind()
        {
            RoleFacade roleFacade = new RoleFacade();
            gv_roles.DataSource = roleFacade.GetAllRoles();
            gv_roles.DataBind();
        }

        protected void btn_add_Click(object sender, EventArgs e)
        {
            RoleFacade roleFacade = new RoleFacade();
            roleFacade.Insert(txt_roleName.Text);
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Alert", @"alert('Success')", true);
        }

        protected void btn_delete_Click(object sender, EventArgs e)
        {
            RoleFacade roleFacade = new RoleFacade();
            roleFacade.Delete(int.Parse(txt_roleName.Text));
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Alert", @"alert('Success')", true);
        }
    }
}